public class StudentSortExample {

    // 定义 Student 类
    public static class Student {
        private String name;
        private int age;

        public Student(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public int getAge() {
            return age;
        }

        @Override
        public String toString() {
            return "Student{name='" + name + "', age=" + age + "}";
        }
    }

    public static void main(String[] args) {
        // 创建 Student 对象数组
        Student[] students = new Student[3];
        students[0] = new Student("玛卡巴卡", 16);
        students[1] = new Student("唔西迪西", 12);
        students[2] = new Student("依古比古", 18);

        // 使用 Comparator 接口的匿名内部类对数组进行排序（按年龄）
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge() - o2.getAge();
            }
        });

        // 遍历并打印排序后的数组
        System.out.println(Arrays.toString(students));
    }
}